package Test;
//同第一个程序 对象转型+继承
public class FatherChildFieldClass {
    public static void main(String[] args) {
        System.out.println("-----------------------------------------------------------------");
        System.out.println("FatherFieldClass fatherFather = new FatherFieldClass();");
        FatherFieldClass fatherFather = new FatherFieldClass();
        System.out.println("main fatherFather.testField: "+ fatherFather.testField);
        fatherFather.testMethod("main Call");
        System.out.println("main fatherFather.modifiedFiled: "+ fatherFather.modifiedFiled);
        
        System.out.println("-----------------------------------------------------------------");
        System.out.println("ChildFieldClass childChild = new ChildFieldClass();");
        ChildFieldClass childChild = new ChildFieldClass();
        System.out.println("main childChild.testField: "+ childChild.testField);
        childChild.testMethod("main Call");
        System.out.println("main childChild.modifiedFiled: "+ childChild.modifiedFiled);
        
        System.out.println("-----------------------------------------------------------------");
        System.out.println("FatherFieldClass fatherChild = new ChildFieldClass();");
        FatherFieldClass fatherChild = new ChildFieldClass();
        System.out.println("main fatherChild.testField: "+ fatherChild.testField);
        fatherChild.testMethod("main Call");
        System.out.println("main fatherChild.modifiedFiled: "+ fatherChild.modifiedFiled);
        System.out.println("-----------------------------------------------------------------");
    }
}
class FatherFieldClass {
    int testField = 2;
    int modifiedFiled = 3;
    public FatherFieldClass() {
        this.testMethod("FatherFieldClass Call");
        // 可忽略this，等价于this.modifiedFiled = 33
        modifiedFiled = 33;
        // new子类获取实例初始化时，调用父类的初始化，this是子类实例，此时调用方法走子类，但是操作字段还是走父类
        System.out.println("FatherFieldClass this: " + this);
        System.out.println("FatherFieldClass testField: " + testField);
        System.out.println("FatherFieldClass this.testField: " + this.testField);
        System.out.println("FatherFieldClass modifiedFiled: " + modifiedFiled);
        System.out.println("FatherFieldClass this.modifiedFiled: " + this.modifiedFiled);
    }
    public void testMethod(String prefix) {
        System.out.println(prefix + " FatherFieldClass testMethod");
        System.out.println(prefix + " FatherFieldClass testMethod modifiedFiled: " + modifiedFiled);
        System.out.println(prefix + " FatherFieldClass testMethod this.modifiedFiled: " + this.modifiedFiled);
    }
}
class ChildFieldClass extends FatherFieldClass {
    int testField = 222;
    int modifiedFiled = 333;
    public ChildFieldClass() {
        this.testMethod("ChildFieldClass Call");
        // 可忽略this，等价于this.modifiedFiled = 3333
        modifiedFiled = 3333;
        System.out.println("ChildFieldClass this: " + this);
        System.out.println("ChildFieldClass testField: " + testField);
        System.out.println("ChildFieldClass this.testField: " + this.testField);
        System.out.println("ChildFieldClass super.testField: " + super.testField);
        System.out.println("ChildFieldClass modifiedFiled: " + modifiedFiled);
        System.out.println("ChildFieldClass this.modifiedFiled: " + this.modifiedFiled);
        System.out.println("ChildFieldClass super.modifiedFiled: " + super.modifiedFiled);
    }

    public void testMethod(String prefix) {
        System.out.println(prefix + " ChildFieldClass testMethod");
        System.out.println(prefix + " ChildFieldClass testMethod modifiedFiled: " + modifiedFiled);
        System.out.println(prefix + " ChildFieldClass testMethod this.modifiedFiled: " + this.modifiedFiled);
    }
}
